<template>
	<view>
		<view class="header">
			<u-tabs itemStyle="padding:30rpx 15px 10rpx 30rpx; padding-right: 15px; height: 44px;width: 17%"
				:list="tabs" @click="click"></u-tabs>
		</view>
		<mescroll-body class="mescroll-body" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption" top="0rpx">
			<view class="scroll-view-item" v-for="(item, index) in list"  :key="item.id"
                @click="$u.route('/pages/Points/Order_List/info', { id: item.id })">
				<view class="scroll_header display_between">
					<view class="order_left">
						<text>订单号：</text>
						<text>{{item.order_ddid}}</text>
					</view>
					<view class="order_right color_666">
						<!-- <text>已关闭</text>
						<u-icon name="trash"></u-icon> -->
						{{item.zt_name}}
					</view>
				</view>
				<view class="order_content">
					<image :src="$imgurl(item.files.split(',')[0])" mode=""></image>
					<view class="content_text">
                        
						<text>{{item.pr_title}}</text>
						<view class="">{{item.sp_title}}</view>
					</view>

				</view>
				<view class="order_cal color_666">
					<text>共计{{item.sum}}件商品，实付金额:</text>
					<text>￥{{item.zong_price}}</text>
				</view>
				<view class="order_but" v-if="item.is_pay==1&&item.is_zt==1" @click.stop=" _ => _">
					<view class="display_center but_B29062 buttom" @click="openOrder(item)">确认收货</view>
					<view class="display_center but_B29062 buttom">
						<a :href="`https://m.kuaidi100.com/app/query/?coname=indexall&nu=${ item.kd_ddid }`">查看物流</a>
					</view>
				</view>
				<u-gap height="10" bgColor="#F8F8F8"></u-gap>
			</view>
		</mescroll-body>
        <HomeNavBtn></HomeNavBtn>

		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	// import member from '@/libs/api/member.js';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				tabs: [{
					name: '全部',
					id: ""
				}, {
					name: '待发货',
					id: '0'
				}, {
					name: '待收货',
					id: '1'
				}, {
					name: '已收货',
					id: '2'
				}],
				order: {
					token: '',
					user_id: 1,
					list_rows: 10,
					page: 1,
					zt: ""
				}, //获取订单接口参数
				list: [],

				// open: {
				// 	token: '',
				// 	user_id: 1,
				// 	id: ''
				// },
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {

				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10, // 每页数据的数量,默认10
						num: 0
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					textNoMore: '没有更多了'
				},
				// setState:true
			}
		},

		methods: {
			click(item) {
				console.log('item', item)
				this.order.zt = item.id
				// this.setCommodity()
				this.downCallback()
			},

			openOrder(a) {
    
				if(!this.setState){
					this.setState= true
					this.$u.request('member.openOrder', {
						id: a.id
					}).then(res => {
                        this.setState=false
                        this.$refs.uToast.show({
                            type: 'success',
                            message: '收货成功',
                            duration:500,
                            complete: () => {
                                
                                this.downCallback()
                            }
                        })
					}).catch(err => {
                        this.setState=false
                    })
				}
			},
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},

			// 下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
			downCallback() {
				this.list = []
				this.mescroll.resetUpScroll();
			},
			/*上拉加载的回调*/
			upCallback(page) {
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				// this.order.token = this.$u.vuex.get('user.token')
				this.$u.request('member.orderLists', {
					list_rows: pageSize,
					page: pageNum,
					user_id: 1,
					zt: this.order.zt,
					// token: this.$u.vuex.get('user.token')
				}).then(res => {
					const list = res.data
					this.list = this.list.concat(list)
					this.mescroll.endSuccess(list.length, list.length, list.length >= page.size)

				}).catch(e => {
					this.$u.toast(e.message || '')
					this.mescroll.endErr()
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./orderList.scss";

	a {
		text-decoration: none;
		color: inherit;
	}
</style>